﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TamTreSoSinh.DBContext;

namespace TamTreSoSinh
{
    public partial class KnownledgePage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadFakeData();
        }

        private void LoadFakeData()
        {
            DBTamTreEntities dbContext = new DBTamTreEntities();
            List<Knownledge> listKnownledge = dbContext.Knownledges.OrderBy(obj => obj.Priority).ToList();

            rptKnownledge.DataSource = listKnownledge;
            rptKnownledge.DataBind();
        }

        protected void rptKnownledge_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Knownledge knownledge = (Knownledge)e.Item.DataItem;
            Label lbl;
            HyperLink hpl;
            Image img;

            hpl = (HyperLink)e.Item.FindControl("hplMainImage");
            hpl.NavigateUrl = @"/KnownledgeDetailPage.aspx?Id=" + knownledge.Id;

            img = (Image)e.Item.FindControl("imgKnownledge");
            img.ImageUrl = knownledge.MainImage;

            lbl = (Label)e.Item.FindControl("lblDate");
            lbl.Text = knownledge.PublishDate.ToString(@"d/M/yyy");

            hpl = (HyperLink)e.Item.FindControl("hplTitle");
            hpl.Text = knownledge.Title;
            hpl.NavigateUrl = @"/KnownledgeDetailPage.aspx?Id=" + knownledge.Id;

            lbl = (Label)e.Item.FindControl("lblOverview");
            lbl.Text = knownledge.Overview;
        }
    }
}